package cn.kust.tarvelService.controller;


import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import cn.kust.tarvelService.pojo.ArticleComment;
import cn.kust.tarvelService.pojo.vo.commentVo;
import cn.kust.tarvelService.service.ArticleCommentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论管理表 前端控制器
 * </p>
 *
 * @author mq
 * @since 2022-07-26
 */
@Api(tags = "评论控制")
@RestController
@RequestMapping("/travelService/article-comment")
public class ArticleCommentController {
    @Autowired
    private ArticleCommentService commentService;


    @GetMapping("/listComment/{articleID}")
    public ResponseResult listCategory(@PathVariable("articleID")  Long articleID){
        List<commentVo> list = commentService.getListComment(articleID);
        System.out.printf("评论回复==>"+list);
        return ResponseResult.success().setData(list);
    }

    @PostMapping("/addComment")
    public ResponseResult addCategory(@RequestBody ArticleComment comment){
        commentService.save(comment);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delCategory(@PathVariable("id") Long id){
        boolean b = commentService.removeById(id);
        if(b){
            return ResponseResult.success();
        }
        return ResponseResult.fail(500,"删除分类失败");
    }

}

